<?php
// +----------------------------------------------------------------------
// | 有理想的地方，地狱都是天堂。
// +----------------------------------------------------------------------
// | Copyright @ df81.com 版权所有
// +----------------------------------------------------------------------
// | 作者: 南国老符 邮箱：1062129401@qq.com
// +----------------------------------------------------------------------

namespace app\admin\controller;
use think\facade\View;

class Social extends Base{
    // 列表
    public function index(){
        return view();
    }

    // 编辑
    public function edit(){
        $type = input('type');

        if(!request()->isPost()){
            return view($type);
        }else{
            // QQ
            $qq_appid = config('social.qq.app_key'); $qq_appkey = config('social.qq.app_secret'); $qq_callback = config('social.qq.callback');
            // 微信
            $weixin_appid = config('social.weixin.app_key'); $weixin_appkey = config('social.weixin.app_secret'); $weixin_callback = config('social.weixin.callback');
            // 新浪
            $sina_appid = config('social.sina.app_key'); $sina_appkey = config('social.sina.app_secret'); $sina_callback = config('social.sina.callback');

            //社交绑定
            switch ($type) {
                case 'qq':
                    $qq_appid = input('qq_appid'); $qq_appkey = input('qq_appkey'); $qq_callback = input('qq_callback');
                    break;
                case 'weixin':
                    $weixin_appid = input('weixin_appid'); $weixin_appkey = input('weixin_appkey'); $weixin_callback = input('weixin_callback');
                    break;
                case 'sina':
                    $sina_appid = input('sina_appid'); $sina_appkey = input('sina_appkey'); $sina_callback = input('sina_callback');
                    break;
            }

            $socialNewContent = "<?php
            //社交绑定
            return [
                'qq' => [
                    'app_key' => '".$qq_appid."',
                    'app_secret' => '".$qq_appkey."',
                    'callback' => '".$qq_callback."',
                ],
                'weixin' => [
                    'app_key' => '".$weixin_appid."',
                    'app_secret' => '".$weixin_appkey."',
                    'callback' => '".$weixin_callback."',
                ],
                'sina' => [
                    'app_key' => '".$sina_appid."',
                    'app_secret' => '".$sina_appkey."',
                    'callback' => '".$sina_callback."',
                ],
                'douyin' => [
                    'app_key' => '',
                    'app_secret' => '',
                    'callback' => '',
                ],
                'facebook' => [
                    'app_key' => '',
                    'app_secret' => '',
                    'callback' => '',
                ],
                'google' => [
                    'app_key' => '',
                    'app_secret' => '',
                    'callback' => '',
                ],
            ];";

            try {
                //修改社交配置
                $socialPath = app()->getConfigPath().'social.php';
                $dofile = new \common\Dofile();
                $dofile->editFile($socialPath,file_get_contents($socialPath),$socialNewContent);
                return json(['code' => 200, 'msg' => lang('c_success'), 'data' => '']);
            } catch (Exception $e) {
                return json(['code' => 500, 'msg' => $e->getMessage(), 'data' => '']);
            }
        }
    }
}